Floating Point Unit

您所在的位置:网站首页 Floating Point Unit Floating Point Unit

Floating Point Unit

2024-07-16 08:37| 来源: 网络整理| 查看: 265

Floating Point Unit¶

This chapter [1] describes the Floating Point Unit (FPU) emulated in EduMIPS64.

In the first paragraph we introduce the double format, the special floating point values defined in the IEEE 754 standard and the exceptions that floating point computations can raise.

In the second paragraph we explain how EduMIPS64 allows users to enable or disable the IEEE floating point traps.

In the third paragraph we describe how double precision numbers and special values can be specified in the source programs.

In the fourth paragraph, we introduce the FCSR register, used by the FPU to represent its state. It contains information about rounding, the boolean results of comparison operations and the policies for handling IEEE floating point exceptions.

In the fifth and last paragraph, we present all the MIPS64 floating point instructions that have been implemented in EduMIPS64.

Before starting the discussion about the FPU, we define the domain of floating point double precision numbers as [-1.79E308,-4.94E-324] ⋃ {0} ⋃ [4.94E-324,1.79E308].

[1]

This chapter is part of the Bachelor’s degree thesis by Massimo Trubia: “Progetto e implementazione di un modello di Floating Point Unit per un simulatore di CPU MIPS64”.

Special values¶

Floating point arithmetics allows the programmer to choose whether to stop the computation or not, if invalid operations are carried on. In this scenario, operations like the division between zeroes or square roots of negative numbers must produce a result that, not being a number (NaN) is treated as somehting different.

NaN or Invalid Operation¶

The IEEE Standard for Floating-Point Arithmetic (IEEE 754) defined that invalid arithmetic operations can either signal the error while the program is running (using a trap for the IEEE exception Invalid Operation) or return as a result the special value QNan (Quit Not a Number). Another NaN value, that inconditionally raises the same trap once it is detected as being one of the operands, is SNan (Signalling Not a Number). This value is seldom used in applications, and historically it has been used to initialize variables.

Zeroes or Underflows¶

Another special value defined by the standard is zero. Since the double format does not include the zero in its domain, it is considered a special value. There is a positive zero and a negative zero: the former is used when a representation of a negative number ∈ ]-4.94E-324,0[) is attempted, and a result is required (as opposed to allowing an Underflow trap), while the latter is used when the number that should be represented is ∈ [0,4.94E-324[, and the Underflow trap is disabled.

Infinites or Overflows¶

When a program attempts to represent a value with an extremely large absolute value (∈ ]-∞,-1.79E308[ ⋃ ]1.79E308,+∞[), that is outside the domain of double values, the CPU returns either -∞ or +∞. The alternative is to trigger a trap for the exceptional Overflow condition.

Infinites can also be returned in case of a division by zero; in that case the sign of the infinite is given by the product of the sign of the zero and the sign of the dividend. The Divide by zero trap can be alternatively raised.

Exception configuration¶

EduMIPS64 allows the user to enable or disable the traps for 4 of the 5 IEEE exceptions, through the FPU Exceptions tab in the Configure → Settings window. If any of them is disabled, the respective special value will be returned (as described in Special values).

The .double directive¶

The .double directive must be used in the .data section of source files, and allows to allocate a memory cell for a double value.

The directive can be used in 2 ways:

variable-name: .double double_number variable-name: .double keyword

where double_number can be represented either in extended notation (1.0,0.003), or in scientific notation(3.7E-12,0.5E32). keyword can be POSITIVEINFINITY, NEGATIVEINFINITY, POSITIVEZERO, NEGATIVEZERO, SNAN e QNAN, thus allowing to directly insert in memory the special values.

The FCSR register¶

The FCSR (Floating point Control Status Register) is the register that controls several functional aspects of the FPU. It is 32 bits long and it is represented in the statistics window.

The FCC field is 8 bits wide, from 0 to 7. The conditional instructions (C.EQ.D,C.LT.D) use it to save the boolean result of comparisons between two registers.

The Cause, Enables and Flag fields handle the dynamics of IEEE exceptions described in Special values. Each of them is composed of 5 bits, V (Invalid Operation), Z (Divide by Zero), O (Overflow), U (Underflow) and I (Inexact); the latter is not yet used.

The Clause field bits are set if the corresponding IEEE exceptions occur during the execution of a program.

The Enable field bits are set through the configuration window and show the IEEE exceptions for which traps are enabled.

The Flag field shows the exceptions that have happened but, since the trap is not enabled for that particular exception, have returned special values (the ones described in Special values).

The RM field describes the rounding method currently in use to convert floating point numbers to integers (see the description of the CVT.L.D instruction).

Instruction set¶

This section describes the MIPS64 FPU instruction implemented by EduMIPS64; they are listed in alphabetic order. The operations performed by the instruction are described using a notation according to which the i-th memory cell is represented as memory[i], and the FCC fields of the FCSR register are FCSR_FCC[cc], cc ∈ [0,7].

In some instructions, to avoid ambiguity, the registers are represented as GPR[i] and FPR[i], i ∈ [0,31], but in most cases we just use the rx or fx notation, with x ∈ {d,s,t}. The three letters are used to indicate the purpose of each register (destination, source, third). Lastly, the values returned by conversion operations are represented with the following notation: convert_conversiontype(register[,rounding_type]), where the rounding_type parameter is optional.

Some examples for the FPU instructions are available at http://www.edumips.org/attachment/wiki/Upload/FPUMaxSamples.rar.

ADD.D fd, fs, ft

Description: fd = fs + ft

Exceptions: Overflow and underflow traps are generated if the result cannot be represented according to IEEE 754. Invalid operation is raised if fs or ft contain QNaN or SNan, or if an invalid operation (+∞ - ∞) is executed.

BC1F cc, offset

Description: if FCSR_FCC[cc] == 0 then branch

If FCSR_FCC[cc] is false, do a PC-relative branch.

Example:

C.EQ.D 7,f1,f2 BC1F 7,label

In this example, C.EQ.D checks if f1 and f2 are equal, writing the results of the comparison in the 7th bit of the FCC field of the FCSR register. After that, BC1F jumps to label if the result of the comparison is 0 (false).

BC1T cc, offset

Description: if FCSR_FCC[cc] == 1 then branch

If FCSR_FCC[cc] is true, do a PC-relative branch.

Example:

C.EQ.D 7,f1,f2 BC1T 7,label

In this example, C.EQ.D checks if f1 and f2 are equal, writing the results of the comparison in the 7th bit of the FCC field of the FCSR register. After that, BC1F jumps to label if the result of the comparison is 1 (false).

C.EQ.D cc, fs, ft

Description: FCSR_FCC[cc] = (fs==ft)

Checks if fs is equal to ft, and saves the result of the comparison in FCSR_FCC[cc]. See examples for BC1T, BC1F.

Exceptions: Invalid Operation can be thrown if fs or ft contain QNaN (trap is triggered if it is enabled) o SNaN (trap is always triggered).

C.LT.D cc, fs, ft

Description: FCSR_FCC[cc] = (fs



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3